#include "pch.h"
#include <string>
#include <tuple>
#include <iostream>
using namespace std;

class ticket
{
public:
	string name;
	string ID;
	string seat;
	bool isSub = false;
	void display()
	{
		if (isSub == true)
		{
			cout << "--------" << endl;
			cout << "姓名：" << name << endl;
			cout << "身份证号：" << ID << endl;
			cout << "座位：" << seat << endl;
			cout << "--------" << endl << endl;
		}
	}
};

class subTicket
{
public:
	static ticket allSeat[20][4];

	static tuple<int, int> toij(string s)
	{
		char _j = s.back();
		int i = atoi(s.substr(0, s.size() - 1).c_str());
		int j;

		switch (_j)
		{
		case 'A':
		{
			j = 0;
			break;
		}
		case 'B':
		{
			j = 1;
			break;
		}
		case 'C':
		{
			j = 2;
			break;
		}
		case 'D':
		{
			j = 3;
			break;
		}
		}

		return make_tuple(i, j);
	}

	static ticket* select(string s)
	{
		int i, j;
		tie(i, j) = subTicket::toij(s);

		if (allSeat[i][j].isSub == false)
		{
			allSeat[i][j].isSub = true;
			allSeat[i][j].seat = s;
			return &allSeat[i][j]; //下面要输入姓名和身份证号
		}
		else
			return nullptr;
	}

	static bool isEmpty(int i, int j)
	{
		return !allSeat[i][j].isSub;
	}

	static bool isEmpty(string s)
	{
		int i, j;
		tie(i, j) = subTicket::toij(s);
		return subTicket::isEmpty(i, j);
	}

	static bool isSmoke(int i) { return i == 19 || i == 20; }
	static bool isSmoke(string s)
	{
		int i;
		tie(i, ignore) = subTicket::toij(s);
		return subTicket::isSmoke(i);
	}

	static void displayAll()
	{
		for (int i = 0; i < 20; i++)
		{
			for (int j = 0; j < 4; j++)
				allSeat[i][j].display();
		}
	}
};
ticket subTicket::allSeat[20][4];

int main()
{
	string f;
	while (1)
	{
		string s;
		cout << "请选择您的座位（如10D）：";	cin >> s;
		if (subTicket::isEmpty(s))
		{
			cout << "您选择的座位为空，";
			if (subTicket::isSmoke(s) == false)
				cout << "为禁烟区，";
			cout << "确认选择吗(Y/N)：";		cin >> f;

			if (f == "Y")
			{
				ticket* t = subTicket::select(s);
				cout << "请输入你的姓名：";	cin >> t->name;
				cout << "请输入你的身份证号：";	cin >> t->ID;
				cout << "订票成功！" << endl;
			}
		}
		else
		{
			cout << "这个座位已经被预订了，请更换其它座位" << endl;
		}

		cout<<"是否要继续预定？(Y/N)：";		cin >> f;
		if (f == "N")
			break;
	}
	subTicket::displayAll();
}